package com.cn.wanxi.service.impl;

import com.cn.wanxi.dao.OnlineDao;
import com.cn.wanxi.dao.impl.OnlineImpl;
import com.cn.wanxi.model.OnlineModel;
import com.cn.wanxi.model.ResultModel;
import com.cn.wanxi.service.OnlineService;

import java.util.List;

/**
 * ResultModel是一个返回的结果集，应该在服务逻辑层进行封装
 * 对于数据持久层，增加一共返回一个什么结果呢？
 */
public class OnlineServiceImpl implements OnlineService {
    private OnlineDao onlineDao = new OnlineImpl();

    @Override
    public ResultModel add(OnlineModel onlineModel) {

//        OnlineDao onlineDao = new OnlineImpl();
//        int count = onlineDao.add(onlineModel);
//        ResultModel resultModel = new ResultModel();
//        resultModel.setCount(count);
//        return resultModel;
        return ResultModel.getResult(onlineDao.add(onlineModel));
    }

    @Override
    public ResultModel update(OnlineModel onlineModel) {
//        OnlineDao onlineDao = new OnlineImpl();
//        int count = onlineDao.update(onlineModel);
//        ResultModel resultModel = new ResultModel();
//        resultModel.setCount(count);
//        return resultModel;
        return ResultModel.getResult(onlineDao.update(onlineModel));
    }

    @Override
    public ResultModel delete(OnlineModel onlineModel) {
//        OnlineDao onlineDao = new OnlineImpl();
//        int count = onlineDao.delete(onlineModel);
//        ResultModel resultModel = new ResultModel();
//        resultModel.setCount(count);
//        return resultModel;
        return ResultModel.getResult(onlineDao.delete(onlineModel));
    }

    @Override
    public ResultModel findById(OnlineModel onlineModel) {
//        OnlineDao onlineDao = new OnlineImpl();
//        OnlineModel model = onlineDao.findById(onlineModel);
//        ResultModel resultModel = new ResultModel();
//        resultModel.setData(model);
//        return resultModel;
        return ResultModel.getResult(onlineDao.findById(onlineModel));
    }

    @Override
    public ResultModel findAll(OnlineModel onlineModel) {
//        OnlineDao onlineDao = new OnlineImpl();
//        List<OnlineModel> list = onlineDao.findAll(onlineModel);
//        ResultModel resultModel = new ResultModel();
//        resultModel.setData(list);
//        return resultModel;
        return ResultModel.getResult(onlineDao.getCount(onlineModel), onlineDao.findAll(onlineModel));
    }

    @Override
    public ResultModel getCount(OnlineModel onlineModel) {
//        OnlineDao onlineDao = new OnlineImpl();
//        int count = onlineDao.getCount(onlineModel);
//        ResultModel resultModel = new ResultModel();
//        resultModel.setCount(count);
//        return resultModel;
        return ResultModel.getResult(onlineDao.getCount(onlineModel));
    }
}
